<template>
    <h2>添加会员会员</h2>

    <table>
        <tr>
            <th>会员名称</th>
            <th> <input type="text" v-model="nn.mname"></th>
        </tr>

        <tr>
            <th>性别</th>
            <th> <input type="radio" :value="1" v-model="nn.sex">男
                <input type="radio" :value="0" v-model="nn.sex">女


            </th>
        </tr>


        <tr>
            <th>手机号</th>
            <th> <input type="text" v-model="nn.phone"></th>
        </tr>
        <tr>
            <th>会员级别</th>
            <th>
                <select v-model="nn.did">
                    <option :value="-1">---请选择---</option>
                    <option v-for="item in bb" :value="item.did">{{ item.dname }}</option>
                </select>

            </th>
        </tr>
        <tr>
            <th>积分</th>
            <th> <input type="text" v-model="nn.jiFen"></th>
        </tr>


        <tr>
            <th>累计消费金额</th>
            <th> <input type="text" v-model="nn.price"> </th>
        </tr>
        <tr>
            <th></th>
            <th> <button @click="Addme">添加</button></th>
        </tr>


    </table>


</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import axios from 'axios';

import { useRouter, createRouter } from 'vue-router';

import { ref } from 'vue'

onMounted(() => {

    XiaLa();
})


const bb = ref([{

    did: -1,
    dname: "",
    xiaoFeie: 0


}])



const XiaLa = () => {

    axios.get('https://localhost:7296/api/Dengji/ShowDengji').then(res => {

        bb.value = res.data
    })
        .catch(error => {
            console.log(error);
        })
}




const nn = ref({
    mname: "",
    sex: 0,
    phone: "",
    did: -1,
    jiFen:"",
    price: 0,
    zhuce: "2024-12-16T02:52:54.219Z",
    isDel: true
})

const router = useRouter();



const ni =/^\d+$/;

const Addme = () => {


    if (nn.value.mname == "") {
        alert('会员姓名不能为空')
        return;
    }

    if (nn.value.phone == "") {
        alert('会员手机号不能为空')
        return;
    }



    if (nn.value.jiFen == "") {
        alert('会员积分不能为空')
        return;
    }





    if (ni.test(nn.value.jiFen)) {
        alert('会员积分不能为空')
        return;
    }









    axios.post('https://localhost:7296/api/Member/AddMe', nn.value).then(res => {


        if (res.data > 0) {
            alert('添加成功')
            router.push('/ShowMe');

        }
        if (res.data == -1) {
            alert('手机号重复')
        }

    })
        .catch(error => {

            console.log(error)
        })
}




</script>